package org.megha.blog.example.concurrency;

/**
 * A thread that increments a given counter a given number of times.
 *
 * @author megha birmiwal
 */
public class IncrementorThread extends Thread {

	private final Counter counter;
	private final int times;

	public IncrementorThread(int times, Counter counter) {
		this.times = times;
		this.counter = counter;
	}

	@Override
	public void run() {
		for (int i = 0; i < times; i++) {
			doIncrement();
		}
	}

	protected void doIncrement() {
		counter.increment();
	}
}
